package org.radar;

import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.StringsCompleter;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;

import java.io.IOException;

/**
 * @author zhangcs
 */
public class Client {

    public static void start() throws IOException {
        Terminal terminal = TerminalBuilder.builder()
                .system(true)
                .build();

        Completer completer = new StringsCompleter("list", "attach", "exit");

        LineReader lineReader = LineReaderBuilder.builder()
                .terminal(terminal)
                .completer(new ArgumentCompleter(completer))
                .build();

        String prompt = "> ";
        while (true) {
            String line;
            try {
                line = lineReader.readLine(prompt);
                if ("exit".equalsIgnoreCase(line)) {
                    System.exit(0);
                }
                System.out.println(line);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
    }

}
